<?php
class loginWidget extends CWidget
{
	public $view = 'login';
  
	public function run()
	{
		$model=new LoginForm;

		// if it is ajax validation request
		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}

		// collect user input data
		if(isset($_POST['LoginForm']))
		{
			$model->attributes=$_POST['LoginForm'];
			// validate user input and redirect to the previous page if valid
			if($model->validate() && $model->login())
				header("location:".Yii::app()->request->getUrl());
		}
// 		echo Yii::app()->request->getUrl();
		$this->render($this->view,array(
			'model'=>$model
		));
	}

}
?>

